package com.donnie.shopping.service.impl;

import com.donnie.shopping.entity.vo.FruitOrderItem;
import com.donnie.shopping.service.ICalculationStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 基础计价策略
 * @author: ChenDeXin
 * @time: 2025/5/20 10:03
 */
@Slf4j
@Service("basicCalculator")
public class BasicPriceCalculator implements ICalculationStrategy {
    /**
     * 计算费用 <br>
     *
     * @param orderItems
     * @return java.lang.Double <br>
     * @date: 2025/5/20 10:05 <br>
     * @author: ChenDeXin <br>
     */
    @Override
    public Double calculate(List<FruitOrderItem> orderItems) {
        return orderItems.stream()
//                .mapToDouble(FruitOrderItem::getCurrentPriceAmt)
                .mapToDouble(item -> {
                    log.info("当前水果：{}，单价：{}，购买量：{}，总价：{}",
                            item.getFruit().name(), item.getFruit().getPrice(), item.getQuantity(), item.getCurrentPriceAmt());

                    return item.getCurrentPriceAmt();
                })
                .sum();
    }
}
